//
//  SiJiCell.m
//  阿帕
//
//  Created 阿帕 on 2019/12/20.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "MyCommentCell.h"

@interface MyCommentCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *dataLabel;
@property (weak, nonatomic) IBOutlet UILabel *orderNumLabel;
@property (weak, nonatomic) IBOutlet UIView *line;
@property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
@property (nonatomic, strong) GQRatingView *ratingView;
@property (weak, nonatomic) IBOutlet UILabel *commentLabel;
@property (nonatomic, strong) UILabel *scoreLabel;
@end

@implementation MyCommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _nicknameLabel.textColor = Dark_TextColor;
    _dataLabel.textColor = Light_TextColor;
    _orderNumLabel.textColor = Light_TextColor;
    _commentLabel.textColor = Dark_TextColor;
    
    _line.backgroundColor = BackgroundColor;
    
    _scoreLabel = [[UILabel alloc] init];
    _scoreLabel.textColor = Light_TextColor;
    _scoreLabel.font = font(13);
    [self.contentView addSubview:_scoreLabel];
    
    //五角星 链式调用 [NSNumber numberWithInt:_model.avgBasicGrade]
    _ratingView = [GQRatingView init]
    .frameChain(CGPointMake(_headImageView.cy_right + 15, _nicknameLabel.cy_y),15)
    .canTouchChain(NO)
    .needIntValueChain(YES)
    .scoreNumChain([NSNumber numberWithFloat:_model.avgBasicGrade])
    .normalColorChain([UIColor cy_colorWithHexString:@"#C0CDDE"])
    .highlightColorChian([UIColor cy_colorWithHexString:@"#FFC000"])
    .scroreBlockChain(^(NSNumber *scoreNumber){
    }).superViewChain(self);
    
    UIView *imgBgView = [[UIView alloc] initWithFrame:CGRectMake(_nicknameLabel.left, _commentLabel.cy_bottom, ScreenW - 70, 75)];
    imgBgView.tag = 100;
    [self addSubview:imgBgView];
}

- (void)buttonClick:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(cellButtonIndexClick:withButton:)]) {
        [self.delegate cellButtonIndexClick:button.tag withButton:button];
    }
}

- (void)setModel:(MyCommentRecordModel *)model {
    
    _model = model;
    
    CGSize shipperNameSize = [DCSpeedy dc_calculateTextSizeWithText:_model.shipperName WithTextFont:14 WithMaxW:1000];
//    CGSize driverNameSize = [DCSpeedy dc_calculateTextSizeWithText:_model.driverName WithTextFont:14 WithMaxW:1000];
    
    //货主信息
    _nicknameLabel.text = [NSString nullToString:CJStringWithFormat(@"%@", _model.shipperName)];
    setNetImage(_headImageView, _model.shipperHeadImg, @"gcy_img_siji_dHead");
    _ratingView.cy_x = _headImageView.cy_right + 15 + shipperNameSize.width;
    _scoreLabel.frame = CGRectMake(_headImageView.cy_right + 15 + shipperNameSize.width + 80, _nicknameLabel.cy_y + 2, 60, 20);
    
    if (_model.commentType == 1) {
        _scoreLabel.text = CJStringWithFormat(@"%.1f",_model.avgShipBasicGrade);
        _ratingView.scoreNum = [NSNumber numberWithFloat: _model.avgShipBasicGrade];
    } else {
        _scoreLabel.text = CJStringWithFormat(@"%.1f",_model.avgBasicGrade);
        _ratingView.scoreNum = [NSNumber numberWithFloat: _model.avgBasicGrade];
    }
        
//    if (_model.commentType == 1) {
//
//
//    } else {
//        _nicknameLabel.text = [NSString nullToString:CJStringWithFormat(@"%@", _model.driverName)];
//        setNetImage(_headImageView, _model.driverHeadImg, @"gcy_img_siji_dHead");
//        _scoreLabel.text = CJStringWithFormat(@"%.1f",_model.avgBasicGrade);
//        _ratingView.scoreNum = [NSNumber numberWithFloat:_model.avgBasicGrade];
//        _ratingView.cy_x = _headImageView.cy_right + 15 + driverNameSize.width;
//        _scoreLabel.frame = CGRectMake(_headImageView.cy_right + 15 + driverNameSize.width + 80, _nicknameLabel.cy_y + 2, 60, 20);
//    }
    
    _scoreLabel.cy_centerY = _nicknameLabel.cy_centerY;
    
    _dataLabel.text = model.gmtCreated;
    _orderNumLabel.text = CJStringWithFormat(@"运输单号：%@", model.orderDetailNumber);
    
    _commentLabel.text = model.commentContent;
    
    CGSize commentSize = [DCSpeedy dc_calculateTextSizeWithText:model.commentContent WithTextFont:14 WithMaxW:ScreenW-70-15];
    _commentLabel.cy_height = commentSize.height + 10;
    
    UIView *imgBgView = [self viewWithTag:100];
    imgBgView.cy_y = _commentLabel.cy_bottom;
    
    if (imgBgView) {
        [imgBgView removeAllSubviews];
    }
//    gcy_icon_plaholder [NSURL URLWithString:model.imageUrlList[i]]
    for (int i=0; i<model.imageUrlList.count; i++) {
        if (i<3) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(85*i, 0, 75, 75)];
            [imageView setImageWithURL:[NSURL URLWithString:model.imageUrlList[i]] placeholder:image(@"gcy_icon_plaholder")];
            [imgBgView addSubview:imageView];
        }
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
